﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Collections;
using System.Reflection;
using UMC.Wiki.Entities;
using UMC.Web;

namespace UMC.Wiki.Activities
{
    class SubjectEffectiveActivity : WebActivity
    {

        public override void ProcessActivity(WebRequest request, WebResponse response)
        {

            var refer_id = UMC.Data.Utility.UInt64Parse(this.AsyncDialog("Refer", g =>
           {
               return new Web.UITextDialog() { Title = "评论的主题" };
           }), 0);//.Value;
            var user = this.Context.Token.Identity();
            if (user.IsAuthenticated == false)
            {
                this.Prompt("不支持匿名点赞，请登录", false);
                // response.Redirect("Account", "Login");
                this.Context.Send("Login",true);

            }

            var ui = this.AsyncDialog("UI", g => this.DialogValue("none"));
            var section = this.AsyncDialog("section", g => this.DialogValue("1"));
            var row = this.AsyncDialog("row", g => this.DialogValue("1"));
            DataFactory.Instance().Comment(new Proposal
            {
                ref_id = refer_id,
                user_id = user.Id,
                Poster = user.Alias,
                CreationDate = DateTime.Now
            });

            var cmt = DataFactory.Instance().Comment(refer_id);
            if (cmt != null)
            {
                var vale = new UMC.Web.WebMeta().Put("section", section).Put("row", row).Put("method", "PUT").Put("reloadSinle", true);

                vale.Put("value", new UMC.Web.WebMeta().Cell(Utility.Comment(cmt, request.Model,request.Url)));

                this.Context.UIEvent("UI.Edit", ui, vale, true);

            }

        }

    }
}